package com.zmyuan.quartz.ram.demo;

import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerFactory;
import org.quartz.SimpleScheduleBuilder;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
import org.quartz.impl.StdSchedulerFactory;

import java.io.FileInputStream;
import java.util.Properties;

import static org.quartz.JobBuilder.newJob;

/**
 * Created by zhudebin on 16/7/19.
 */
public class Demo1 {

    public static void main(String[] args) throws Exception {
        Properties properties = new Properties();
        properties.load(Demo1.class.getResourceAsStream("/quartz.properties"));
//        properties.setProperty(
//                StdSchedulerFactory.PROP_SCHED_MAKE_SCHEDULER_THREAD_DAEMON,
//                "false");


        StdSchedulerFactory schedFact = new StdSchedulerFactory(properties);


        Scheduler sched = schedFact.getScheduler();
        sched.start();

        // define the job and tie it to our HelloJob class
        JobDetail job = newJob(HelloJob.class)
                .withIdentity("myJob", "group1")
                .usingJobData("squidFlowId", 111)
                .build();

        // 触发时间点
        SimpleScheduleBuilder simpleScheduleBuilder = SimpleScheduleBuilder
                .simpleSchedule()
                .withRepeatCount(1).withIntervalInSeconds(15);
        Trigger trigger = TriggerBuilder.newTrigger().withIdentity("trigger1", "group1")
                .startNow().withSchedule(simpleScheduleBuilder).build();

        // Tell quartz to schedule the job using our trigger

        sched.scheduleJob(job, trigger);

        System.out.println("schedule job");

    }

}


